/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.CustomerManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.SQLException;
/*    */ import java.util.List;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONArray;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class ListCompanyName extends AbstractAction
/*    */ {
/* 34 */   private static Logger logger = Logger.getLogger(ListCompanyName.class
/* 35 */     .getName());
/*    */ 
/*    */   public ListCompanyName(AbstractHttpServlet servlet)
/*    */   {
/* 38 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 44 */     response.setContentType("text/html;charset=utf-8");
/* 45 */     User user = super.getLoginUser(request);
/* 46 */     PrintWriter out = response.getWriter();
/* 47 */     JSONArray array = new JSONArray();
/* 48 */     String term = Util.getURLParameter(request.getParameter("term"));
/*    */ 
/* 51 */     boolean isFromImport = "1".equals(request.getParameter("isFromImport"));
/* 52 */     CustomerManager manager = new CustomerManager();
/* 53 */     int companyId = super.getLoginUser(request).companyId;
/*    */ 
/* 55 */     if (isFromImport) {
/* 56 */       String ids = Util.getURLParameter(request.getParameter("ids"));
/* 57 */       List items = manager.getCustomerNameByIds(
/* 58 */         companyId, ids);
/* 59 */       JSONObject jsonObject = new JSONObject();
/* 60 */       if (items == null) {
/* 61 */         jsonObject.put("error", "1");
/*    */       } else {
/* 63 */         jsonObject.put("error", "0");
/* 64 */         jsonObject.put("items", items);
/*    */       }
/* 66 */       out.println(jsonObject);
/* 67 */       out.flush();
/* 68 */       out.close();
/* 69 */       return;
/*    */     }
/*    */     try
/*    */     {
/* 73 */       array = JSONArray.fromObject(manager.getCompanyName(companyId, 
/* 74 */         term, user.isAdmin, user.userId));
/*    */     } catch (DBException|SQLException e) {
/* 76 */       logger.warn("get company name failed", e);
/*    */     }
/* 78 */     out.println(array);
/* 79 */     out.flush();
/* 80 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ListCompanyName
 * JD-Core Version:    0.6.1
 */